﻿using BCCommon;
using BCDto.TMS.Packing.PackingConfigOverwrite;
using BCService.TMS.Packing.PackingConfigOverwrite;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.Packing.PackingConfig
{
    /// <summary>
    /// 包装材料配置重写
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class PackingConfigOverwriteController : ManagementBaseController
    {
        private readonly IPackingConfigOverwriteService packingConfigOverwriteService;

        public PackingConfigOverwriteController(IPackingConfigOverwriteService packingConfigOverwriteService)
        {
            this.packingConfigOverwriteService = packingConfigOverwriteService;
        }

        /// <summary>
        /// 添加包装材料配置重写
        /// </summary>
        /// <param name="requestDto">包装材料配置记录添加信息</param>
        /// <response code="201">添加包装材料配置重写</response>
        /// <returns></returns>
        [Log("添加包装材料配置重写")]
        [HttpPost]
        [ProducesResponseType(typeof(PackingConfigOverwriteDto), 201)]
        public IActionResult Post([FromBody] PackingConfigOverwriteRequestDto requestDto)
        {
            var result = this.packingConfigOverwriteService.Add(this.Admin, requestDto);
            return Ok(result);
        }

        /// <summary>
        /// 修改包装材料配置重写
        /// </summary>
        /// <param name="packingConfigOverwriteId">包装材料配置重写Id</param>
        /// <param name="putDto">包装材料配置记录修改信息</param>
        /// <response code="200">修改包装材料配置重写</response>
        /// <returns></returns>
        [Log("修改包装材料配置重写")]
        [HttpPut("{packing_config_overwrite_id}")]
        [ProducesResponseType(typeof(PackingConfigOverwriteDto), 200)]
        public IActionResult Put([FromRoute(Name = "packing_config_overwrite_id")]int packingConfigOverwriteId,
            [FromBody] PackingConfigOverwritePutDto putDto)
        {
            var result = this.packingConfigOverwriteService.Update(this.Admin, packingConfigOverwriteId, putDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 删除包装材料配置重写
        /// </summary>
        /// <param name="packingConfigOverwriteId">包装材料配置重写Id</param>
        /// <response code="204">删除包装材料配置重写</response>
        /// <returns></returns>
        [Log("删除包装材料配置重写")]
        [HttpDelete("{packing_config_overwrite_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "packing_config_overwrite_id")] int packingConfigOverwriteId)
        {
            this.packingConfigOverwriteService.Delete(this.Admin, packingConfigOverwriteId);
            return NoContent();
        }

        /// <summary>
        /// 启用/禁用包装材料配置重写
        /// </summary>
        /// <param name="packingConfigOverwriteId">包装材料配置重写Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="200">启用/禁用包装材料配置重写</response>
        /// <returns></returns>
        [HttpPut("[action]/{packing_config_overwrite_id}/{enabled}")]
        [ProducesResponseType(typeof(PackingConfigOverwriteDto), 200)]
        [Log("启用/禁用包装材料配置重写")]
        public IActionResult Enabled([FromRoute(Name = "packing_config_overwrite_id")] int packingConfigOverwriteId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            var result = this.packingConfigOverwriteService.UpdateEnabled(this.Admin, packingConfigOverwriteId, enabled);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取包装材料配置重写记录
        /// </summary>
        /// <param name="packingCategoryConfigId">包装材料分类配置Id</param>
        /// <param name="packingTitle">包装材料标题</param>
        /// <param name="provinceCode">省份编码</param>
        /// <param name="cityCode">市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="enabled">是否启用</param>
        /// <param name="createStartDate">创建开始日期</param>
        /// <param name="createEndDate">创建结束日期</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取包装材料配置重写记录</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<PackingConfigOverwriteViewDto>), 200)]
        public IActionResult Query([FromQuery(Name = "packing_category_config_id")] int? packingCategoryConfigId,
            [FromQuery(Name = "packing_title")] string packingTitle,
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "city_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "create_start_date")] DateTime? createStartDate,
            [FromQuery(Name = "create_end_date")] DateTime? createEndDate,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            long? agentRecordId = null;
            if (this.Admin.AgentRecord != null)
            {
                agentRecordId = this.Admin.AgentRecord.AgentRecordId;
            }
            var result = this.packingConfigOverwriteService.Query(agentRecordId, packingCategoryConfigId, packingTitle, provinceCode, cityCode, countyCode, enabled, createStartDate, createEndDate, pageIndex, pageSize);
            return this.Ok(result);
        }
    }
}
